<% content_for :sidebar do %>
  <%= sidebar_button_link 'Edit Person', edit_person_path(@person) if can? :edit, @person %>
  <%= sidebar_button_link 'New Certification', new_person_cert_path(@person) if can? :create, Cert %>
  <%= sidebar_button_link 'New Availability', new_person_availability_path(@person) if can? :create, Availability %>
  <%= sidebar_button_link 'New Timecard', new_person_timecard_path(@person) if can? :create, Timecard %>
  <br>
  <%= image_tag @person.portrait_url if @person.portrait.file.present? %>
  <table class="qr">
    <% @qr.modules.each_index do |x| %>
        <tr>
          <% @qr.modules.each_index do |y| %>
              <% if @qr.dark?(x,y) %>
                  <td class="black"/>
              <% else %>
                  <td class="white"/>
             <% end %>
          <% end %>
        </tr>
    <% end %>
  </table>
<% end %>

<h2><%= @person.shortrank %> <%= @person.fullname %> (<%= @person.icsid %>)</h2>

<% if @person.start_date %>
  <p><b>Start Date:</b> <%= @person.start_date %> (<%= distance_of_time_in_words(((@person.end_date) || Date.today), @person.start_date) if @person.start_date %>)</p>
<% end %>

<p>
  <b>Status:</b> <%= success_or_warning_label(@person.status, 'Active') %>
</p>

<div id="channels">
  <ul>
    <% @person.channels.each do |channel| %>
      <% if channel.content.present? %>
        <li>
          <%# This should be moved into a presenter to just return the right content %>
          <% if channel.phone? %>
            <%= number_to_phone(channel.content, area_code: true) %>
            <%= "on #{channel.carrier}" if channel.carrier.present? %>
          <% else %>
            <%= channel.content %>
          <% end %>
        </li>
      <% end %>
    <% end %>
  </ul>
</div>

<% if @person.titles.any? %>
  <div class="accordion">
    <% @person.titles.each do |title| %>
      <% if @person.qualified?(title.name) then %>
        <h3>Qualified for <%= title.name %></h3>
        <div>No missing certifications</div>
      <% else %>
        <h3>NOT qualified for <%= title.name %></h3>
        <div>
          Skills Missing:
          <ul class="missing_titles">
            <% @person.missing_skills(title).each do |missing_skill| %>
                 <li><%= missing_skill %></li>
            <% end %>
          </ul>
        </div>
      <% end %>
    <% end %>
  </div>
  <br/><br/>
<% end %>

<div class="accordion">
  <h3>Skills (<%= @person.valid_skills.uniq.count %>)</h3>
  <div>
    <table class="table table-striped table-bordered">
      <tbody>
        <%= render(@person.valid_skills.uniq) || raw("No skills yet !") %>
      </tbody>
    </table>
  </div>

  <h3>Courses (<%= @person.courses.uniq.count %>)</h3>
  <div>
    <table class="table table-striped table-bordered">
      <tbody>
        <%= render(@person.courses.uniq) || raw("No courses yet !") %>
      </tbody>
    </table>
  </div>

  <h3>Certifications (<%= @person.certs.uniq.count %>)</h3>
  <div>
    <table class="table table-striped table-bordered">
      <tbody>
        <%= render(@person.certs) || raw("No certifications yet !") %>
      </tbody>
    </table>
  </div>

  <h3>Items (<%= @person.items.uniq.count %>)</h3>
  <div>
    <ul>
      <%= render(@person.items) || raw("No Items Found !") %>
    </ul>
  </div>

  <h3>Availabilities (<%= @person.availabilities.uniq.count %>)</h3>
  <div>
    <ul>
      <%= render(:partial => "availabilities/availabilities_table_for_people",
                 :locals => { :availabilities => @person.availabilities }) || raw("No Availabilities Found !") %>
    </ul>
  </div>

  <h3>Timecards (<%= @person.timecards.count %>)</h3>
  <div>
    <ul>
      <%= render 'timecards/timecards_table', timecards: @person.timecards.most_recent.uniq %>
    </ul>
  </div>

  <h3>Comments (<%= @person.comments.count %>)</h3>
  <div>
    <ul>
      <%= render(:partial => "comments/comments_table_for_people",
                 :locals => { :comments => @person.comments }) %>
    </ul>
  </div>
</div>

<% content_for :parking do %>
  <table class="table table-striped table-bordered">
    <thead>
      <tr>
        <th>Skills Missing for Police</th>
      </tr>
    </thead>
    <tbody>
      <%#= render(Title.find(1).skills - @person.skills) %>
    </tbody>
  </table>
  <span class="label label-danger">This comes out red
    <span class="label label-warning">
      Person qualified, but some certification is expiring soon
    </span><br/>
<% end %>
<br/>
<p>
  Created <%= @person.created_at %><br/>
  Last Modified <%= @person.updated_at %></br>
  Last Editor <%= @last_editor %>
</p>
